<?php
/**
 *  NevuxBB - Free Forum Software
 *  Copyright (C) 2008, 2010 NevuxBB (No one specific author)*  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Header File
 * File: header.php
 * Purpose: Serve as the ACP header
 * Todo: Protect it
 *
 */

// basic header requirements
ob_start();

// load the langauge file for the ACP
$core_lang_system->reset();
$core_lang_system->add_file('acp');

// set the actual script name
$script_name = explode('/', $_SERVER['SCRIPT_NAME']);

// do we have an admin session?
if(CoreUserSystem::isLoggedIn() && CoreUserSystem::getUserlevel() == 3) {
	// begin generating the header
	$core_template_system->newTemplate(BASE_PATH . '/acp/template/header.html');
	
	// we need to load ACP ONLY settings from the DB
	$result = Db_Abstraction::query('SELECT * FROM `nbb_settings` WHERE `settings_area` = 1');
	
	// loop through these and build an array
	$acp_reserved_settings = array();
	while($row = DB_Abstraction::fetch_assoc($result)) {
		// expand array
		$acp_reserved_settings[$row['settings_name']] = array('data' => $row['settings_data']);
	}
	
	// is an admin, do we have a session?
	if(CoreUserSystem::getAdminSession() === false && array_search('acp-login.php', $script_name) === false) {
		// isn't set, redirect to the login screen
		header('Location: acp-login.php');
		exit();
	}
	
	// are we trying to login again?
	if(CoreUserSystem::getAdminSession() === true && array_search('acp-login.php', $script_name)) {
		// redirect them somewhere else
		header('Location: index.php');
		exit();
	}
} else {
	// shouldn't be here at all
	header('Location: ../index.php');
	exit();
}

?>